
package JET.UtilPanels.Trees;

import JET.Frames.DataModels.SceneTreeModel;
import JET.ImageUtils.ImageUtils;
import JET.physics.*;
import JET.physics.bodies.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;

/**
 *
 * @author 057Ry
 */

enum SceneTreeNodeType {
    Scene,
    SpringBody,
    Spring,
    Springs,
    Mass,
    Masses,
    Vec,
    Value,
    Text,
    Boolean
}

public class SceneTreeCellRenderer extends JLabel implements TreeCellRenderer {

    private HashMap<SceneTreeNodeType, ImageIcon> icons;
    ImageIcon dot = null;
    Color bgColor = Color.WHITE;
    Color bgSelectedColor = new Color(49, 106, 197);

    boolean selected;

    public SceneTreeCellRenderer() {
        loadIcons();
    }

    private void loadIcons() {
        dot = ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/dot15x15.png");
        //System.out.println()
        icons = new HashMap<SceneTreeNodeType, ImageIcon>();
        icons.put(SceneTreeNodeType.Scene, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/scene.png"));
        icons.put(SceneTreeNodeType.SpringBody, dot);
        icons.put(SceneTreeNodeType.Spring, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/spring15x15.png"));
        icons.put(SceneTreeNodeType.Springs, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/springs29x21.png"));
        icons.put(SceneTreeNodeType.Mass, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/mass14x15.png"));
        icons.put(SceneTreeNodeType.Masses, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/masses14x15.png"));
        icons.put(SceneTreeNodeType.Vec, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/vec15x15.png"));
        icons.put(SceneTreeNodeType.Value, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/value15x15.png"));
        icons.put(SceneTreeNodeType.Text, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/text15x15.png"));
        icons.put(SceneTreeNodeType.Boolean, ImageUtils.loadImageIconFromResources("/JET/Images/sceneTreeIcons/boolean24x14.png"));
    }

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        if (selected) bgColor = bgSelectedColor;
        else          bgColor = Color.WHITE;

        this.setText(value.toString());

        if (value instanceof SceneTreeModel.SceneRootNode) setIcon(icons.get(SceneTreeNodeType.Scene));
        else if (value instanceof SpringBody) setIcon(icons.get(SceneTreeNodeType.SpringBody));
        else if (value instanceof Spring) setIcon(icons.get(SceneTreeNodeType.Spring));
        //else if (value instanceof SpringBody.SpringsTreeNode) setIcon(icons.get(SceneTreeNodeType.Springs));
        else if (value instanceof Mass) setIcon(icons.get(SceneTreeNodeType.Mass));
        else if (value instanceof SceneTree.VecTreeNode) setIcon(icons.get(SceneTreeNodeType.Vec));
        else if (value instanceof Mass.MassTreeNode ||
                 value instanceof Spring.KsTreeNode || value instanceof Spring.KdTreeNode || value instanceof Spring.KtTreeNode || value instanceof Spring.StartLengthTreeNode)
            setIcon(icons.get(SceneTreeNodeType.Value));
        //else if (value instanceof SpringBody.MassesTreeNode) setIcon(icons.get(SceneTreeNodeType.Masses));
        else if (value instanceof SpringBody.NameTreeNode || value instanceof Mass.NameTreeNode || value instanceof Spring.NameTreeNode)
            setIcon(icons.get(SceneTreeNodeType.Text));
        else if (value instanceof Mass.MoveableTreeNode || value instanceof Spring.TearableTreeNode || value instanceof Spring.AliveTreeNode)
            setIcon(icons.get(SceneTreeNodeType.Boolean));
        else
            setIcon(dot);

        this.selected = selected;

        return this;
    }

    public void paint(Graphics g) {
        g.setColor(bgColor);
        g.fillRect(0, 0, getWidth(), getHeight());

        if (selected)
            this.setForeground(Color.WHITE);
        else
            this.setForeground(Color.BLACK);

        super.paint(g);
    }
}

